package com.example.review;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.example.review.base.BaseActivity;
import com.example.review.databinding.ActivityViewBindingBinding;

public class ViewBindingActivity extends BaseActivity {

    private ActivityViewBindingBinding binding;

    @Override
    //活动创建的时候调用
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /*
        这个是findViewById的方法
        */
        setContentView(R.layout.activity_main);


        //viewbinding方式
        binding = ActivityViewBindingBinding.inflate(getLayoutInflater());
        //获取根视图
        View view = binding.getRoot();
        setContentView(view);
        //使用绑定类的实例来引用任何View(XML中必须添加id)
        binding.text1.setText("这是在代码中指定的文字");
        binding.text1.setTextColor(Color.GRAY);
        binding.text1.setTextSize(30);
        binding.text1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(ViewBindingActivity.this, "你点击了文本框", Toast.LENGTH_SHORT).show();
            }
        });
    }

}
